<template>
  <window ref="win" :title="'重新排第'+(classLecture ? classLecture.lectureNo : '')+'讲老师'">
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
      <div class="widget am-cf">
        <div class="widget-body  am-fr">

          <div class="am-g am-form ">

            <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
              <div class="am-form-group">
                <input type="text" class="am-input-lg" name="selectedTeacher" v-model="query.teacherName"
                       placeholder="请输入教师姓名"/>
              </div>
            </div>

            <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
              <div class="am-form-group">
                <input type="text" class="am-input-lg" name="idNo" v-model="query.idNo" placeholder="请输入身份证号码"/>
              </div>
            </div>

            <div class="am-u-sm-12 am-u-md-12 am-u-lg-3 am-u-end">
              <div class="am-form-group">
                <button type="button" class="am-btn am-btn-default am-btn-success" @click="search">
                  <span class="am-icon-search"></span>查询
                </button>
              </div>
            </div>
          </div>

          <!--table-->
          <div class="am-u-sm-12">
            <el-table
              :data="tableData"
              border
              stripe
              height="400"
              style="min-width: 100%">
              <el-table-column type="expand">
                <template scope="scope">
                  <calendar :teacherId="scope.row.teacherId"></calendar>
                </template>
              </el-table-column>
              <el-table-column
                prop="teacherName"
                label="教师姓名"
                min-width="100">
              </el-table-column>
              <el-table-column
                prop="teachSubjectNames"
                label="任教科目"
                min-width="100">
              </el-table-column>
              <el-table-column
                label="入职时间"
                min-width="100">
                <template scope="scope">
                  {{scope.row.joinTime | formatDate}}
                </template>
              </el-table-column>
              <el-table-column
                prop="phoneNo"
                label="电话号码"
                min-width="100">
              </el-table-column>

              <el-table-column
                label="请选择临调原因"
                min-width="130">
                <template scope="scope">
                  <el-select v-model="scope.row.remark" placeholder="请选择临调原因">
                    <el-option
                      key="有薪假"
                      label="有薪假"
                      value="有薪假">
                    </el-option>

                    <el-option
                      key="无薪假"
                      label="无薪假"
                      value="无薪假">
                    </el-option>

                  </el-select>
                </template>
              </el-table-column>
               <el-table-column
                label="后续讲次延用"
                min-width="120">
                <template scope="scope">
                  <div class="am-form">
                    <label class="am-radio-inline">
                      <input type="radio" :name="'status-'+scope.row.teacherId" value="true" v-model="scope.row.useInFollowingLectrue">是
                    </label>
                    <label class="am-radio-inline">
                      <input type="radio" :name="'status-'+scope.row.teacherId" value="false" v-model="scope.row.useInFollowingLectrue">否
                    </label>
                  </div>
                </template>
              </el-table-column>

              <el-table-column
                label="操作"
                width="100">
                <template scope="scope">
                  <el-button size="small" @click.native="ok(scope.row)">确定</el-button>
                </template>
              </el-table-column>


            </el-table>
          </div>

          <div class="am-u-lg-12 am-cf">
            <div class="am-fr">
              <pagination v-bind:total="total" v-bind:pageNo="pageNo" v-bind:pageSize="pageSize"
                          @paging="loadTableData"/>
            </div>
          </div>

        </div>
      </div>
    </div>
  </window>
</template>

<script>
  import io from '../../lib/io'
  import Pagination from '../base/Pagination'
  import Calendar from './CalendarForTeacher'

  export default{
    data: function () {
      return {
        tableData: [],
        teacherData: [],
        total: 0,
        pageSize: 10,
        pageNo: 1,
        query: {},
        selectedTeacher: [],
        courseClass: {},
        classLecture: {},
        remark: ''
      }
    },
    components: {
      Pagination, 'calendar': Calendar
    },
    methods: {
      search: function () {
        this.loadTableData(this.pageNo)
      },
      loadTableData: function (pageNo) {
        var _this = this
        _this.pageNo = pageNo || _this.pageNo || 1
        io.post(io.apiAdminTeacherListForClassArrangement, $.extend({
          areaTeamId: _this.courseClass.areaTeamId,
          //busTeamId:_this.courseClass.busTeamId,
          teachGradeNames: _this.courseClass.gradeName,
          teachSubjectNames: _this.courseClass.subjectName,
          pageNo: _this.pageNo,
          pageSize: _this.pageSize,
          accessType: 0
        }, _this.query), function (ret) {
          if (ret.success) {
            _this.total = ret.data.total
            ret.data.list.map((item)=>{
              item.useInFollowingLectrue = 'false'
              item.remark = ''
            })
            _this.tableData = ret.data.list
          } else {
            _this.$alert(ret.desc)
          }
        })
      },
      ok: function (teacher) {
        var _this = this
        if(!teacher.remark){
          _this.$alert('请选择临调原因')
          return false
        }
        if(!teacher.useInFollowingLectrue){
          _this.$alert('请选择讲次是否延用')
          return false
        } 
        io.post(io.apiAdminRearrangeTeacherForLecture, {
          classLectureId: this.classLecture.classLectureId,
          teacherId: teacher.teacherId,
          updateAfterLecture: false,
          remark: teacher.remark,
          useInFollowingLectrue:teacher.useInFollowingLectrue=='true'?true:false,
        }, function (ret) {
          if (ret.success) {
            _this.$emit('ok')
            _this.$refs.win.close()
          } else {
            _this.$alert(ret.desc || '处理失败')
          }
        })
      },
      show: function () {
        this.$refs.win.show({width: 1000})
        this.loadTableData()
      }
    }
  }
</script>

